/*
 * table_GblLinkage.c
 *
 *  Created on: 2012/03/29
 *      Author: guanxiaoying
 */
#include "../../parser/coredef.h"

#define TableSize  (sizeof(GBLLINKAGE))
#define TableType  PGBLLINKAGE
#define stTable stGblLinkageManager.memoryBlocks
#define maxTable stGblLinkageManager.maxRecordNum
#define  maxNumPerBlk  (stGblLinkageManager.astMaxNum_Block)
/*KIND_GBLLINKAGE*/
typedef struct _GBLLINKAGE
{
	AST		astSymDefInfo;
	BOOL	bRef;
	BOOL    bExternal;
	BOOL    bFunction;
} GBLLINKAGE, *PGBLLINKAGE;
/* get the object */
static TABLEMANAGER stGblLinkageManager = {
//		U4                  usIdx;
		0,
//		PSZ				    con_pszName;    constant
		__FILE__,
//		U2					con_usSize;		constant
		TableSize,
//		U2					block_num;	　　　　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_Block;     １回設定のみ
		0,
//		S4					astTabNum_LastPage; 　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_LastPage;     Reset clear  際　要
		0,
//		U4					ulMaxByte;	　　　　　　　　　　クリアしない
		0,
//		U4					con_minPageSize;　　　　　　　　　　constant
		0
};
static VOID resetListener( U4  procid, U2 index )
{
	if( procid == stGblLinkageManager.u4Idx )
	{
		if( index > 0 && index < MAX_VOLUMN_OF_TABLE )
		{
			stTable[ index-1] = NULL;
		}
	}
}
static TableType core_getTable( AST index )
{
	TableType temp = (TableType)Check_Com( &stGblLinkageManager,  resetListener, index );
	if( temp != NULL ){ return &temp[index%maxNumPerBlk]; } return NULL;
}
static BOOL ClearTable( VOID )
{
	return Clear_Com( &stGblLinkageManager );
}
static BOOL ResetTable( VOID )
{
	return Reset_Com( &stGblLinkageManager );
}
static BOOL AllocTable( AST astReqArg )
{
	return AllocTable_Com( &stGblLinkageManager, astReqArg, resetListener );
}
static AST getMaxLineNum( VOID ){
	return maxTable;
}
/* give up the way that defining get/set function pointer in the struct,
 * because of memory volume.
 */
//	IDX_DECSYMCHAIN
/*  get method */
static AST  getDefinition( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astSymDefInfo;
}
/* set method */
static AST  setDefinition( AST index, AST idx )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		assert_index( maxTable, index, idx );
		return 0;
	}
	return pTbl->astSymDefInfo = idx;
}

/*  get method */
static BOOL  getReferInfo( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->bRef;
}
/* set method */
static BOOL  setReferInfo( AST index, BOOL value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		assert_index( maxTable, index, idx );
		return 0;
	}
	return pTbl->bRef = value;
}
/*  get method */
static BOOL  getExternalFlag( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->bExternal;
}
/* set method */
static BOOL  setExternalFlag( AST index, BOOL value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		assert_index( maxTable, index, idx );
		return 0;
	}
	return pTbl->bExternal = value;
}
/*  get method */
static BOOL  getFunctionFlag( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->bFunction;
}
/* set method */
static BOOL  setFunctionFlag( AST index, BOOL value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		assert_index( maxTable, index, idx );
		return 0;
	}
	return pTbl->bFunction = value;
}

const GBLLINKAGE_ACCESS stGblLinkageAccess = {

				ClearTable,
				ResetTable,
				AllocTable,
				getMaxLineNum,

		{
				getDefinition,
				setDefinition
		},

		{
				getReferInfo,
				setReferInfo
		},

		{
				getExternalFlag,
				setExternalFlag
		},
		{
				getFunctionFlag,
				setFunctionFlag
		}
};
/* end of file */

